#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@IDE     ：PyCharm 
@Author  ：kiway
@Date    ：2024/5/1 10:08 
"""

from cmrp import Strategy__
import pandas as pd
from cmrp.logger import pretty_print
import random
import time
import numpy as np


class MyStrategy(Strategy__):
    #
    # def on_bar(self, symbol, bars):
    #     print(f"时间是{int(time.time() * 1000)}，  消息体{bars}")

    # #
    # def on_orderbook(self, symbol, orderbooks):
    #     print(orderbooks)

    # def on_aggTrade(self, symbol, aggTrade):
    #     # pass
    #     print(aggTrade)
    #
    # #
    # def on_tick(self, symbol, ticks):
    #     # pretty_print(self.balance_info_df)
    #     print(f"时间是{int(time.time() * 1000)}  消息体{ticks}")
    #

    def on_all_bar(self, spot_bars, future_bars):

        # print(self.record.position_info())
        # future_df = pd.concat(future_bars, axis=1)
        # print(future_df)
        # spot_df = pd.concat(spot_bars, axis=1)
        # print(spot_df)

        # a = random.uniform(0, 1)
        # # print(future_bars)
        close_dict = {}
        for kline in future_bars:

            if np.isnan(kline["close"]):
                return

            close_dict[kline.name] = kline["close"]

        data = pd.DataFrame(pd.Series(close_dict))
        data.columns = ["price"]

        data["value"] = 0.

        a = random.randint(0, 10) / 10

        data.iat[1, 1] = a
        data.iat[0, 1] = 1 - a

        print(data)

        self.place_order_from_all_bar(data)
